function calColWidth(colLabel: any, tableData: any) {
    let canvas = document.createElement("canvas");
    let context: any = canvas.getContext("2d");
    context.font = window.getComputedStyle(document.body).font; 
    let res: any = {};
    // const PADDING = 20;
    const PADDING = 0
    for (let key in colLabel) {
        res[key] = {
            label: colLabel[key],
            width: Math.ceil(context.measureText(colLabel[key]).width + PADDING)
        };
    } 
    for (let i = 0; i < tableData.length; i++) {
        for (let key in colLabel) {
            const curContent = tableData[i][key] != null ? String(tableData[i][key]) : '';
            const curWidth = Math.ceil(context.measureText(curContent).width + PADDING);
            if (curWidth > res[key].width) {
                res[key].width = curWidth;
            }
        }
    } 
    return res;
}

export default calColWidth;
